#include "testmenucount.h"
#include <qaction.h>
#include <qmenu.h>
#include <qdebug.h>

testmenucount::testmenucount(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    OnInitDialog();
}

void testmenucount::OnInitDialog()
{
    auto _lst{GetActions(ui.menuBar)};
    for (const auto i : _lst)
        qDebug() << "ac name: " << i->text() << " ";
    int a = 10;
}

QList<QAction*> testmenucount::GetActions(QMenu* menu)
{
	QList<QAction*>_lst{};
	if (menu)
	{
		auto _menu_lst = menu->findChildren<QMenu*>();
		auto _ac_lst = menu->actions();
		QList<QAction*>_temp{};

        for (const auto i : _menu_lst)
        {
            _temp += i->actions();
            _ac_lst.removeOne(i->menuAction());
        }
        _lst = _ac_lst + _temp;
	}
	return _lst;
}

QList<QAction*> testmenucount::GetActions(QMenuBar* menubar)
{
    QList<QAction*>_temp{};

    auto _lst = menubar->findChildren<QMenu*>(QString(), Qt::FindDirectChildrenOnly);
    for (const auto i : _lst)
        _temp += GetActions(i);
    return _temp;
}
